package com.akkainaction.tool.io.streams.actor;

import akka.Done;
import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;
import akka.stream.Materializer;
import akka.stream.javadsl.RunnableGraph;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Source;

import java.util.concurrent.CompletionStage;

public class TestStreams {

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sys");
        //materializer主要用来给流分配Actor并驱动其执行
        Materializer materializer = ActorMaterializer.create(system);
        Source<Integer, NotUsed> source = Source.range(1, 5);
        Sink<Integer, CompletionStage<Done>> sink = Sink.foreach(System.out::println);
        RunnableGraph<NotUsed> graph = source.to(sink);
        graph.run(materializer);
    }
}
